<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Help extends Base_Controller {
  
    public function articlelist() {
        $limit = 5;
        $type = $this->uri->segment(3);
        $page = $this->uri->segment(4);
        if($type=='question'||$type==1){
            $tid = 1;
        } else {
            $tid = 2;
        }
        $query = $this->db->select('id')->where("tid={$tid}")->get('qbjh_article');
        $sum = count($query->result_array());
        
        $this->load->library('pagination');
        $config['base_url'] = site_url('help/articlelist').'/'.$tid;
        $config['first_link'] = '首页';
        $config['last_link'] = '末页';
        $config['next_link'] = '>>';
        $config['attributes'] = array('class' => 'cur');
        $config['cur_tag_open'] = '<b class="cur active">';
        $config['cur_tag_close'] = '</b>';
        $config['prev_link'] = '<<';
        $config['total_rows'] = $sum;
        $config['per_page'] = $limit;
        $this->pagination->initialize($config);
        
        $query = $this->db->select('*')->where("tid={$tid}")->order_by('createtime DESC')->limit($limit,$page)->get('qbjh_article');
        $article_list = $query->result_array();

        
        $query = $this->db->select('id,tid,title')->where("tid={$tid}")->order_by('readamount DESC')->limit(10)->get('qbjh_article');
        $hot_list = $query->result_array();
        $this->data['articlelist'] = $article_list;
        $this->data['hotlist'] = $hot_list;
        $this->load->view('public/head', $this->data);
        $this->load->view('pages/list');
        $this->load->view('public/foot');
    }
    
    public function content(){
        $tid = $this->uri->segment(3);
        $id = $this->uri->segment(4);
        $query = $this->db->select('id,tid,title')->where("tid={$tid}")->order_by('readamount DESC')->limit(10)->get('qbjh_article');
        $hot_list = $query->result_array();
        $query = $this->db->select('*')->where("id={$id}")->get('qbjh_article');
        $content = $query->row_array();
        $content['readamount']++;
        $this->db->where("id={$id}")->update('qbjh_article',['readamount'=>$content['readamount']]);
        $this->data['content'] = $content;
        $this->data['hotlist'] = $hot_list;
        $this->load->view('public/head', $this->data);
        $this->load->view('pages/article');
        $this->load->view('public/foot');
    }
    
    public function softwarelist(){
        $limit = 1;
        $page = $this->uri->segment(3);
        $query = $this->db->select('id')->get('qbjh_software');
        $sum = count($query->result_array());
        
        $this->load->library('pagination');
        $config['base_url'] = site_url('help/softwarelist');
        $config['first_link'] = '首页';
        $config['last_link'] = '末页';
        $config['next_link'] = '>>';
        $config['attributes'] = array('class' => 'cur');
        $config['cur_tag_open'] = '<b class="cur active">';
        $config['cur_tag_close'] = '</b>';
        $config['prev_link'] = '<<';
        $config['total_rows'] = $sum;
        $config['per_page'] = $limit;
        $this->pagination->initialize($config);
        
        $query = $this->db->select('*')->limit($limit,$page)->get('qbjh_software');
        $software_list = $query->result_array();
        $this->data['softwarelist'] = $software_list;
        $this->load->view('public/head', $this->data);
        $this->load->view('pages/down');
        $this->load->view('public/foot');
    }


}
